# -*- coding: utf-8 -*-
from service.login import *
from service.query_basic import *
from service.query_basic_update import *
from service.query_room import *
from service.modify_unpay_order import *
from service.modify_table import *
from service.modify_unpay_order import *
from service.uploadtest import *

def application(environ, start_response):
    
    if environ['PATH_INFO'] == None:        
        return say_bad(environ, start_response, 'bad request')
        
    path_info = str(environ['PATH_INFO'])[1:]
    
    if path_info == 'login':
        return Login.application(environ, start_response)
    elif path_info == 'query_basic_update':
        return QueryBasicUpdate.application(environ, start_response)
    elif path_info == 'query_basic':
        query = QueryBasic()
        return query.application(environ, start_response)
    elif path_info == 'basiccai_class':
        query = QueryBasic()
        return query.basiccai_class(environ, start_response)
    elif path_info == 'basicorders_new':
        query = QueryBasic()
        return query.basicorders_new(environ, start_response)
    elif path_info == 'basicorders_pay':
        query = QueryBasic()
        return query.basicorders_pay(environ, start_response)
    elif path_info == 'basicdishs':
        query = QueryBasic()
        return query.basicdishs(environ, start_response)
    elif path_info == 'basicsubdishs':
        query = QueryBasic()
        return query.basicsubdishs(environ, start_response)
    elif path_info == 'basiccai_leibie':
        query = QueryBasic()
        return query.basiccai_leibie(environ, start_response)
    elif path_info == 'basiccai_makedetail':
        query = QueryBasic()
        return query.basiccai_makedetail(environ, start_response)
    elif path_info == 'basiccai_name':
        query = QueryBasic()
        return query.basiccai_name(environ, start_response)
    elif path_info == 'basicdele_tbl':
        query = QueryBasic()
        return query.basicdele_tbl(environ, start_response)
    elif path_info == 'basicfloor_tables':
        query = QueryBasic()
        return query.basicfloor_tables(environ, start_response)
    elif path_info == 'basicmake_tbl':
        query = QueryBasic()
        return query.basicmake_tbl(environ, start_response)
    elif path_info == 'basicprint_tab':
        query = QueryBasic()
        return query.basicprint_tab(environ, start_response)
    elif path_info == 'basicreason_tbl':
        query = QueryBasic()
        return query.basicreason_tbl(environ, start_response)
    elif path_info == 'basicroom_tables':
        query = QueryBasic()
        return query.basicroom_tables(environ, start_response)
    elif path_info == 'basictaocan_ks_detail':
        query = QueryBasic()
        return query.basictaocan_ks_detail(environ, start_response)
    elif path_info == 'basictaocan_ks_main':
        query = QueryBasic()
        return query.basictaocan_ks_main(environ, start_response)
    elif path_info == 'basictaocan_tbl':
        query = QueryBasic()
        return query.basictaocan_tbl(environ, start_response)
    elif path_info == 'basicunit_caitbl':
        query = QueryBasic()
        return query.basicunit_caitbl(environ, start_response)
    elif path_info == 'basicuser_info':
        query = QueryBasic()
        return query.basicuser_info(environ, start_response)
    elif path_info == 'basiczuof_class':
        query = QueryBasic()
        return query.basiczuof_class(environ, start_response)
    elif path_info == 'basiccai_classfather':
        query = QueryBasic()
        return query.basiccai_classfather(environ, start_response)
    elif path_info == 'basicview_dian':
        query = QueryBasic()
        return query.basicview_dian(environ, start_response)
    elif path_info == 'query_room':
        return QueryRoom.application(environ, start_response)
    elif path_info == 'query_unpay_order':
        return QueryUnpayOrder.application(environ, start_response)
    elif path_info == 'modify_table':
        return ModifyTable.application(environ, start_response)
    elif path_info == 'modify_unpay_order':
        return ModifyUnpayOrder.application(environ, start_response)
    elif path_info == "admin/user_admin" :
        pass
    elif path_info == "uploadtest":
        return UploadTest.application(environ, start_response)
    else:    
        return say_bad(environ, start_response, 'request unsupported')
    
    
 
def say_bad(environ, start_response, msg):
    status = '200 ok'
    output = msg

    response_headers = [('Content-type', 'text/plain'),
                ('Content-Length', str(len(output)))]

    start_response(status, response_headers)

    return [output]      